import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class ScreenCapture {
public static void main(String[] args) {
	saveScreen("capturedImage");
}

public static boolean saveScreen(String fileNameJpeg) {
	try {
		// Get the "actual" screen size
		Dimension scr = Toolkit.getDefaultToolkit().getScreenSize();
		System.out.println("(" + scr.width + "," + scr.height + ")");
			// Allocate a Robot instance, and do a screen capture
			Robot robot = new Robot();
			Rectangle rect = new Rectangle(0, 0, scr.width, scr.height);
			BufferedImage image = robot.createScreenCapture(rect);
			// Save the captured image to file with ImageIO
			ImageIO.write(image, "jpeg", new File(fileNameJpeg + ".jpg"));
			return true;
		} catch (Exception ex) {
			System.out.println(ex.toString());
			return false;
		}
	}
}